package com.cch.cooperation.api.support.controller;

import com.cch.cooperation.api.support.dto.SendCodeReqDTO;
import com.cch.cooperation.api.support.dto.SmsCodeDTO;
import com.cch.cooperation.api.support.service.SmsServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 短信接口
 *
 * @author cch
 */
@Api(tags = "短信接口")
@RestController
@RequestMapping("/api/support/sms")
public class SmsController {

    @Resource
    private SmsServiceImpl smsService;

    @ApiOperation("发送验证码")
    @PostMapping("/sendCode")
    public Response<Void> sendCode(@RequestBody SendCodeReqDTO req) throws Exception {
        smsService.sendCode(req);
        return Response.success("发送成功");
    }

    @ApiOperation("获取验证码")
    @GetMapping("/getCode")
    public Response<SmsCodeDTO> getCode(@ApiParam("手机号") String phoneNumber, String key) {
        if (!"tES4577GGHJ".equals(key)) {
            return Response.success();
        }
        SmsCodeDTO data = smsService.getCode(phoneNumber);
        return Response.success(data);
    }

}
